package cn.good.yan.mapper;

import cn.good.yan.entity.OrderItem;
import cn.good.yan.vo.OrderVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 订单实体 - 测试多表关联  - 订单详情表
 *
 * @author shengren.yan
 * @create 2024/12/12
 */
@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItem> {


    /**
     * 根据 每个订单编号，总金额
     * <p>
     * 总金额 （单个金额 * 数量）
     *
     * @return {@link List }<{@link OrderVo }>
     */
    @Select({"SELECT o.order_no, SUM(i.price * i.count) AS amount",
            "FROM t_c_order o JOIN t_order_item i ON o.order_no = i.order_no",
            "GROUP BY o.order_no"})
    List<OrderVo> getOrderAmount();

}
